/*
package cn.htu.msj.web.support;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.bind.support.WebRequestDataBinder;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.annotation.ModelFactory;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import java.lang.reflect.Parameter;

public class PreloadArgumentResolver implements HandlerMethodArgumentResolver {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        if (methodParameter.hasParameterAnnotation(Preload.class)) {
            return true;
        }
        return false;
    }

    @Override
    public Object resolveArgument(MethodParameter methodParameter,
                                  ModelAndViewContainer modelAndViewContainer,
                                  NativeWebRequest nativeWebRequest,
                                  WebDataBinderFactory webDataBinderFactory) throws Exception {

        Preload parameterAnnotation = methodParameter.getParameterAnnotation(Preload.class);

        String key = parameterAnnotation.value();

        String value = nativeWebRequest.getParameter(key);

        Object targetObject = null;

        if (value != null) {

            Parameter parameter = methodParameter.getParameter();

            Class<? extends Parameter> clazz = parameter.getClass();

            Query query = sessionFactory.getCurrentSession().createQuery("FROM " + clazz.getSimpleName() + "WHERE " + key + " = :valu");

            query.setParameter("valu", value);

            targetObject = query.uniqueResult();
        }
        String name = ModelFactory.getNameForParameter(methodParameter);

        WebDataBinder binder = webDataBinderFactory.createBinder(nativeWebRequest, targetObject, name);

        Object target = binder.getTarget();

        if (target != null) {

            ((WebRequestDataBinder) binder).bind(nativeWebRequest);
        }
        return target;
    }
}
*/
